from ultralytics import YOLO

model = YOLO('yolov8n-seg.yaml')

# Train the model
results = model.train(
  data='datasets/Drawing Annotation Recognition2.v1i.yolov12/data.yaml',
  epochs=600, 
  batch=256, 
  imgsz=640,
  scale=0.5,  # S:0.9; M:0.9; L:0.9; X:0.9
  mosaic=1.0,
  mixup=0.0,  # S:0.05; M:0.15; L:0.15; X:0.2
  copy_paste=0.1,  # S:0.15; M:0.4; L:0.5; X:0.6
  device="0",
)

# Evaluate model performance on the validation set
metrics = model.val(task='segment')

# Perform object detection on an image
results = model("datasets/Drawing Annotation Recognition2.v1i.yolov12/test/images"
"/Untitled_png.rf.d59ec9e6949e043c86f6c3ad8e33bcd6.jpg",task='segment')
results[0].show()
for result in results:
    masks = result.masks  # 获取分割掩码
    if masks is not None:
        print("Segmentation Masks:", masks)